package com.wephone.Student.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.loopj.android.http.RequestParams;
import com.wephone.Student.R;
import com.wephone.Student.bean.GetApplyInfoResponse;
import com.wephone.Student.network.HttpClient;
import com.wephone.Student.network.MyResponseHandler;
import com.wephone.Student.util.Constants;
import com.wephone.Student.util.ShareReferenceUtil;

public class FanliActivity extends BaseActivity {
	
	private MyResponseHandler getHandler(){
		MyResponseHandler handler = new MyResponseHandler(FanliActivity.this,GetApplyInfoResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					GetApplyInfoResponse res = (GetApplyInfoResponse)response;
					if(res.getIds()!=null){
						if(res.getIds().getConfirm().equals("0")){
							Toast.makeText(getApplicationContext(), "您的申请还未审核通过，请耐心等待!", Toast.LENGTH_SHORT).show();
						}else{
							startActivity(new Intent(getApplicationContext(),FanliDetail1Activity.class));
						}
					}
				}
			}
		};
		return handler;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fanli);
		
		init();
	}
	
	
	
//	@Override
//	protected void onResume() {
//		super.onResume();
//		
//		if(ShareReferenceUtil.getApplyIds(getApplicationContext())<0){
//			findViewById(R.id.fanli_layout_1).setVisibility(View.VISIBLE);
//			findViewById(R.id.fanli_layout_2).setVisibility(View.GONE);
//		}else{
//			findViewById(R.id.fanli_layout_1).setVisibility(View.GONE);
//			findViewById(R.id.fanli_layout_2).setVisibility(View.VISIBLE);
//		}
//	}

	private void init(){
		findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		findViewById(R.id.fanli_layout_1).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(ShareReferenceUtil.getApplyIds(getApplicationContext())>0){
					Toast.makeText(getApplicationContext(), "请不要重复提交请求", Toast.LENGTH_SHORT).show();
				}else{
					startActivity(new Intent(getApplicationContext(),AskForFanli1Activity.class));
				}
//				startActivity(new Intent(getApplicationContext(),AskForFanli2Activity.class));
			}
		});
		findViewById(R.id.fanli_layout_2).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(ShareReferenceUtil.getApplyIds(getApplicationContext())<0){
					Toast.makeText(getApplicationContext(), "请先提交申请", Toast.LENGTH_SHORT).show();
				}else{
					RequestParams params = new RequestParams();
					params.put("aId", ""+ShareReferenceUtil.getApplyIds(getApplicationContext()));
					HttpClient.getInstance().get(Constants.API_GET_APPLY_INFO_URL, params, getHandler());
				}
			}
		});
	}
	

}
